package main

import (
	"fmt"
)

func main() {
	s := "ababd"
	fmt.Println(longestPalindrome(s))
	fmt.Println(longestPalindrome2(s))
}

func longestPalindrome(s string) string {
	result := ""
	length := len(s)
	for i := 0; i < length; i++ {
		tmp := find(s, i, i)
		if len(tmp) > len(result) {
			result = tmp
		}

		tmp = find(s, i, i+1)
		if len(tmp) > len(result) {
			result = tmp
		}

	}
	return result

}

func find(s string, left, right int) string {
	for left >= 0 && right < len(s) && s[left] == s[right] {
		left--
		right++
	}
	return s[left+1 : right]
}
